#导包
from rest_framework import serializers
#导入数据库类
from myapp.models import  *
from myapp.my_md5 import make_password


class UserSer1(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'




class UpdateUserSerializer(serializers.ModelSerializer):
    #通过设置 class Meta
    class Meta:
        #设置关联模型
       model = User
        # 设置字段   __all__表示所有字段   exclude = ['']  排除列表中的字段，剩余的字段都显示
       fields = ['password','img']

    # def update(self, instance, validated_data):
    #     validated_data['password'] = make_password(validated_data.get('password'))
    #     User.objects.update(**validated_data)
    #     return instance

        #read_only_fields = ('')  只读字段


class UpdateUserSerializerGet(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['img']



class GoodsSer(serializers.ModelSerializer):

    #声明字段
	class Meta:
            model = Goods
            fields = "__all__"

class CategorySer(serializers.ModelSerializer):

    #声明字段
    class Meta:
        model = Category
        fields = "__all__"
